import $ from 'jquery';
import store from '.';
const moudleAdmin = {
    state: {
        id: "",
        adminName: "",
        isLogin: "",
        token: "",
        role: "",
    },
    getters: {
    },
    mutations: {
        update(state, data) {
            $.ajax({
                url: "http://124.221.73.180:3001/adminInfo/getInfoByToken/",
                type: "post",
                headers: {
                    "satoken": data.token,
                },
                cache: false,
                async: false,
                success(resp) {
                    state.id = resp.id;
                    state.adminName = resp.name;
                    state.token = data.token;
                    state.isLogin = true;
                    state.role = resp.role;
                }
            })
            if (data.remember == true) {
                localStorage.setItem("isLogin", true);
                localStorage.setItem("token", data.token);
            }
        },
        logout(state) {
            localStorage.clear();
            state.id = "";
            state.adminName = "";
            state.token = "";
            state.isLogin = false;
            state.role = "";
        }
    },
    actions: {
        login(context, data) {
            console.log(data);
            context.commit("update", data);//传来token和是否记住我,根据token获取信息;
        },
        logout(context) {
            context.commit("logout");
        },
        test(state) {
            console.log(state.isLogin + "哈哈哈哈哈哈");
        }
    },
    modules: {
    }
};
export default moudleAdmin;
